package com.excilys.training.ebanking.web.test;

import static org.junit.Assert.fail;
import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;

public class ExportExcelIT extends SeleniumTest {

	@Before
	public void setUp() throws Exception {
		selenium = new DefaultSelenium("localhost", 4444, "*chrome",
				"http://localhost:8080/");
		selenium.start();
	}

	@Test
	public void testExportExcel() throws Exception {
		selenium.open("/web/");
		selenium.type("id=j_username", "romain");
		selenium.type("id=j_password", "test");
		for (int second = 0;; second++) {
			if (second >= 60)
				fail("timeout");
			try {
				if (selenium
						.isElementPresent("//form[@id='loginForm']/table/tbody/tr[4]/td"))
					break;
			} catch (Exception e) {
			}
			Thread.sleep(1000);
		}

		selenium.click("name=validation");
		selenium.waitForPageToLoad("30000");
		Assert.assertTrue(selenium.isTextPresent("Solde courant"));
		selenium.click("link=LIVRE JEUNE");
		selenium.waitForPageToLoad("30000");
		Assert.assertTrue(selenium.isTextPresent("Solde actuel"));
		for (int second = 0;; second++) {
			if (second >= 60)
				fail("timeout");
			try {
				if ("".equals(selenium
						.getText("//form[@action='/web/client/compte/2/mois.html']")))
					break;
			} catch (Exception e) {
			}
			Thread.sleep(1000);
		}

	}

}